home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / kaneko16.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  19KB  |  748 lines

  1. /***************************************************************************
  2.  
  3.                         -= Kaneko 16 Bit Games =-
  4.  
  5.                 driver by    Luca Elia (eliavit@unina.it)
  6.  
  7.  
  8. Note:    if MAME_DEBUG is defined, pressing Z with:
  9.  
  10.         Q            shows the background
  11.         W/E/R/T        shows the foreground (priority 0/1/2/3)
  12.         A/S/D/F        shows the sprites    (priority 0/1/2/3)
  13.  
  14.         Keys can be used togheter!
  15.  
  16.                             [ 1 High Color Layer ]
  17.  
  18.     [Background 0]    (Optional)
  19.  
  20.                             [ 4 Scrolling Layers ]
  21.  
  22.     [Background 1]
  23.     [Foreground 1]
  24.     [Background 2?]    Unused
  25.     [Foreground 2?]    Unused
  26.  
  27.         Layer Size:                512 x 512
  28.         Tiles:                    16x16x4
  29.         Tile Format:
  30.  
  31.                 0000.w            fedc ba-- ---- ----        unused?
  32.                                 ---- --98 ---- ----        Priority
  33.                                 ---- ---- 7654 32--        Color
  34.                                 ---- ---- ---- --1-        Flip X
  35.                                 ---- ---- ---- ---0        Flip Y
  36.  
  37.                 0002.w                                    Code
  38.  
  39.  
  40.  
  41.                             [ 1024 Sprites ]
  42.  
  43.     Sprites are 16x16x4 in the older games 16x16x8 in gtmr>mr2
  44.  
  45. Offset:            Format:                        Value:
  46.  
  47. 0000.w            Attribute (type 0, older games: shogwarr, berlwall)
  48.  
  49.                     f--- ---- ---- ----        Multisprite: Use Latched Code + 1
  50.                     -e-- ---- ---- ----        Multisprite: Use Latched Color (And Flip?)
  51.                     --d- ---- ---- ----        Multisprite: Use Latched X,Y As Offsets
  52.                     ---c ba-- ---- ----
  53.                     ---- --98 ---- ----        Priority?
  54.                     ---- ---- 7654 32--        Color
  55.                     ---- ---- ---- --1-        X Flip
  56.                     ---- ---- ---- ---0        Y Flip
  57.  
  58.  
  59.                 Attribute (type 1: gtmr, gtmr2)
  60.  
  61.                     f--- ---- ---- ----        Multisprite: Use Latched Code + 1
  62.                     -e-- ---- ---- ----        Multisprite: Use Latched Color (And Flip?)
  63.                     --d- ---- ---- ----        Multisprite: Use Latched X,Y As Offsets
  64.                     ---c ba-- ---- ----        unused?
  65.                     ---- --9- ---- ----        X Flip
  66.                     ---- ---8 ---- ----        Y Flip
  67.                     ---- ---- 76-- ----        Priority
  68.                     ---- ---- --54 3210        Color
  69.  
  70. 0002.w                                        Code
  71. 0004.w                                        X Position << 6
  72. 0006.w                                        Y Position << 6
  73.  
  74. Note:
  75.     type 2 sprites (berlwall) are like type 0 but the data is held
  76.     in the last 8 bytes of every 16.
  77.  
  78.  
  79. **************************************************************************/
  80.  
  81. #include "vidhrdw/generic.h"
  82.  
  83. /* Variables only used here: */
  84.  
  85. static struct tilemap *bg_tilemap, *fg_tilemap;
  86. static struct osd_bitmap *kaneko16_bg15_bitmap;
  87. static int flipsprites;
  88.  
  89. #ifdef MAME_DEBUG
  90. static int debugsprites;    // for debug
  91. #endif
  92.  
  93. /* Variables that driver has access to: */
  94.  
  95. unsigned char *kaneko16_bgram, *kaneko16_fgram;
  96. unsigned char *kaneko16_layers1_regs, *kaneko16_layers2_regs, *kaneko16_screen_regs;
  97. unsigned char *kaneko16_bg15_select, *kaneko16_bg15_reg;
  98. int kaneko16_spritetype;
  99.  
  100. /* Variables defined in drivers: */
  101.  
  102.  
  103. /***************************************************************************
  104.  
  105.                                 Palette RAM
  106.  
  107. ***************************************************************************/
  108.  
  109. WRITE_HANDLER( kaneko16_paletteram_w )
  110. {
  111.     /*    byte 0        byte 1        */
  112.     /*    xGGG GGRR   RRRB BBBB    */
  113.     /*    x432 1043     2104 3210    */
  114.  
  115.     int newword, r,g,b;
  116.  
  117.     COMBINE_WORD_MEM(&paletteram[offset], data);
  118.  
  119.     newword = READ_WORD (&paletteram[offset]);
  120.     r = (newword >>  5) & 0x1f;
  121.     g = (newword >> 10) & 0x1f;
  122.     b = (newword >>  0) & 0x1f;
  123.  
  124.     palette_change_color( offset/2,     (r * 0xFF) / 0x1F,
  125.                                      (g * 0xFF) / 0x1F,
  126.                                      (b * 0xFF) / 0x1F     );
  127. }
  128.  
  129. WRITE_HANDLER( gtmr_paletteram_w )
  130. {
  131.     if (offset < 0x10000)    kaneko16_paletteram_w(offset, data);
  132.     else                    COMBINE_WORD_MEM(&paletteram[offset], data);
  133. }
  134.  
  135.  
  136.  
  137.  
  138. /***************************************************************************
  139.  
  140.                             Video Registers
  141.  
  142. ***************************************************************************/
  143.  
  144. /*    [gtmr]
  145.  
  146. Initial self test:
  147. 600000:4BC0 94C0 4C40 94C0-0404 0002 0000 0000
  148. 680000:4BC0 94C0 4C40 94C0-1C1C 0002 0000 0000
  149.  
  150. 700000:0040 0000 0001 0180-0000 0000 0000 0000
  151. 700010:0040 0000 0040 0000-0040 0000 2840 1E00
  152.  
  153. Race start:
  154. 600000:DC00 7D00 DC80 7D00-0404 0002 0000 0000
  155. 680000:DC00 7D00 DC80 7D00-1C1C 0002 0000 0000
  156.  
  157. 700000:0040 0000 0001 0180-0000 0000 0000 0000
  158. 700010:0040 0000 0040 0000-0040 0000 2840 1E00
  159.  
  160. */
  161.  
  162. READ_HANDLER( kaneko16_screen_regs_r )
  163. {
  164.     return READ_WORD(&kaneko16_screen_regs[offset]);
  165. }
  166.  
  167. WRITE_HANDLER( kaneko16_screen_regs_w )
  168. {
  169.     int new_data;
  170.  
  171.     COMBINE_WORD_MEM(&kaneko16_screen_regs[offset],data);
  172.     new_data  = READ_WORD(&kaneko16_screen_regs[offset]);
  173.  
  174.     switch (offset)
  175.     {
  176.         case 0x00:    flipsprites = new_data & 3;    break;
  177.     }
  178.  
  179.     logerror("CPU #0 PC %06X : Warning, screen reg %04X <- %04X\n",cpu_get_pc(),offset,data);
  180. }
  181.  
  182.  
  183.  
  184. /*    [gtmr]
  185.  
  186.     car select screen scroll values:
  187.     Flipscreen off:
  188.         $6x0000: $72c0 ; $fbc0 ; 7340 ; 0
  189.         $72c0/$40 = $1cb = $200-$35    /    $7340/$40 = $1cd = $1cb+2
  190.  
  191.         $fbc0/$40 = -$11
  192.  
  193.     Flipscreen on:
  194.         $6x0000: $5d00 ; $3780 ; $5c80 ; $3bc0
  195.         $5d00/$40 = $174 = $200-$8c    /    $5c80/$40 = $172 = $174-2
  196.  
  197.         $3780/$40 = $de    /    $3bc0/$40 = $ef
  198.  
  199. */
  200.  
  201. WRITE_HANDLER( kaneko16_layers1_regs_w )
  202. {
  203.     COMBINE_WORD_MEM(&kaneko16_layers1_regs[offset],data);
  204. }
  205.  
  206. WRITE_HANDLER( kaneko16_layers2_regs_w )
  207. {
  208.     COMBINE_WORD_MEM(&kaneko16_layers2_regs[offset],data);
  209. }
  210.  
  211.  
  212. /* Select the high color background image (out of 32 in the ROMs) */
  213. READ_HANDLER( kaneko16_bg15_select_r )
  214. {
  215.     return READ_WORD(&kaneko16_bg15_select[0]);
  216. }
  217. WRITE_HANDLER( kaneko16_bg15_select_w )
  218. {
  219.     COMBINE_WORD_MEM(&kaneko16_bg15_select[0],data);
  220. }
  221.  
  222. /* ? */
  223. READ_HANDLER( kaneko16_bg15_reg_r )
  224. {
  225.     return READ_WORD(&kaneko16_bg15_reg[0]);
  226. }
  227. WRITE_HANDLER( kaneko16_bg15_reg_w )
  228. {
  229.     COMBINE_WORD_MEM(&kaneko16_bg15_reg[0],data);
  230. }
  231.  
  232.  
  233.  
  234. /***************************************************************************
  235.  
  236.                         Callbacks for the TileMap code
  237.  
  238.                               [ Tiles Format ]
  239.  
  240. Offset:
  241.  
  242. 0000.w            fedc ba-- ---- ----        unused?
  243.                 ---- --98 ---- ----        Priority
  244.                 ---- ---- 7654 32--        Color
  245.                 ---- ---- ---- --1-        Flip X
  246.                 ---- ---- ---- ---0        Flip Y
  247.  
  248. 0002.w                                    Code
  249.  
  250. ***************************************************************************/
  251.  
  252.  
  253. /* Background */
  254.  
  255. #define BG_GFX (0)
  256. #define BG_NX  (0x20)
  257. #define BG_NY  (0x20)
  258.  
  259. static void get_bg_tile_info(int tile_index)
  260. {
  261.     int code_hi = READ_WORD(&kaneko16_bgram[4*tile_index + 0]);
  262.     int code_lo = READ_WORD(&kaneko16_bgram[4*tile_index + 2]);
  263.     SET_TILE_INFO(BG_GFX, code_lo,(code_hi >> 2) & 0x3f);
  264.     tile_info.flags     =    TILE_FLIPXY( code_hi & 3 );
  265. }
  266.  
  267. WRITE_HANDLER( kaneko16_bgram_w )
  268. {
  269. int old_data, new_data;
  270.  
  271.     old_data  = READ_WORD(&kaneko16_bgram[offset]);
  272.     COMBINE_WORD_MEM(&kaneko16_bgram[offset],data);
  273.     new_data  = READ_WORD(&kaneko16_bgram[offset]);
  274.  
  275.     if (old_data != new_data)
  276.         tilemap_mark_tile_dirty(bg_tilemap,offset/4);
  277. }
  278.  
  279.  
  280.  
  281.  
  282.  
  283. /* Foreground */
  284.  
  285. #define FG_GFX (0)
  286. #define FG_NX  (0x20)
  287. #define FG_NY  (0x20)
  288.  
  289. static void get_fg_tile_info(int tile_index)
  290. {
  291.     int code_hi = READ_WORD(&kaneko16_fgram[4*tile_index + 0]);
  292.     int code_lo = READ_WORD(&kaneko16_fgram[4*tile_index + 2]);
  293.     SET_TILE_INFO(FG_GFX, code_lo,(code_hi >> 2) & 0x3f);
  294.     tile_info.flags     =    TILE_FLIPXY( code_hi & 3 );
  295.     tile_info.priority    =    (code_hi >> 8) & 3;
  296. }
  297.  
  298. WRITE_HANDLER( kaneko16_fgram_w )
  299. {
  300. int old_data, new_data;
  301.  
  302.     old_data  = READ_WORD(&kaneko16_fgram[offset]);
  303.     COMBINE_WORD_MEM(&kaneko16_fgram[offset],data);
  304.     new_data  = READ_WORD(&kaneko16_fgram[offset]);
  305.  
  306.     if (old_data != new_data)
  307.         tilemap_mark_tile_dirty(fg_tilemap,offset/4);
  308. }
  309.  
  310.  
  311.  
  312. WRITE_HANDLER( kaneko16_layers1_w )
  313. {
  314.     if (offset < 0x1000)    kaneko16_fgram_w(offset,data);
  315.     else
  316.     {
  317.         if (offset < 0x2000)    kaneko16_bgram_w((offset-0x1000),data);
  318.         else
  319.         {
  320.             COMBINE_WORD_MEM(&kaneko16_fgram[offset],data);
  321.         }
  322.     }
  323. }
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332. int kaneko16_vh_start(void)
  333. {
  334.     bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,
  335.                                 TILEMAP_TRANSPARENT, /* to handle the optional hi-color bg */
  336.                                 16,16,BG_NX,BG_NY);
  337.  
  338.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,
  339.                                 TILEMAP_TRANSPARENT,
  340.                                 16,16,FG_NX,FG_NY);
  341.  
  342.     if (!bg_tilemap || !fg_tilemap)
  343.         return 1;
  344.  
  345.     {
  346. /*
  347. gtmr background:
  348.         flipscreen off: write (x)-$33
  349.         [x=fetch point (e.g. scroll *left* with incresing x)]
  350.  
  351.         flipscreen on:  write (x+320)+$33
  352.         [x=fetch point (e.g. scroll *right* with incresing x)]
  353.  
  354.         W = 320+$33+$33 = $1a6 = 422
  355.  
  356. berlwall background:
  357. 6940 off    1a5 << 6
  358. 5680 on        15a << 6
  359. */
  360.         int xdim = Machine->drv->screen_width;
  361.         int ydim = Machine->drv->screen_height;
  362.         int dx, dy;
  363.  
  364. //        dx   = (422 - xdim) / 2;
  365.         switch (xdim)
  366.         {
  367.             case 320:    dx = 0x33;    dy = 0;        break;
  368.             case 256:    dx = 0x5b;    dy = -8;    break;
  369.  
  370.             default:    dx = dy = 0;
  371.         }
  372.  
  373.         tilemap_set_scrolldx( bg_tilemap, -dx,        xdim + dx -1        );
  374.         tilemap_set_scrolldx( fg_tilemap, -(dx+2),    xdim + (dx + 2) - 1 );
  375.  
  376.         tilemap_set_scrolldy( bg_tilemap, -dy,        ydim + dy -1 );
  377.         tilemap_set_scrolldy( fg_tilemap, -dy,        ydim + dy -1);
  378.  
  379.         bg_tilemap->transparent_pen = 0;
  380.         fg_tilemap->transparent_pen = 0;
  381.         return 0;
  382.     }
  383. }
  384.  
  385.  
  386.  
  387.  
  388. /* Berlwall has an additional hi-color background */
  389.  
  390. void berlwall_init_palette(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  391. {
  392.     int i;
  393.  
  394.     palette += 2048 * 3;    /* first 2048 colors are dynamic */
  395.  
  396.     /* initialize 555 RGB lookup */
  397.     for (i = 0; i < 32768; i++)
  398.     {
  399.         int r,g,b;
  400.  
  401.         r = (i >>  5) & 0x1f;
  402.         g = (i >> 10) & 0x1f;
  403.         b = (i >>  0) & 0x1f;
  404.  
  405.         (*palette++) = (r << 3) | (r >> 2);
  406.         (*palette++) = (g << 3) | (g >> 2);
  407.         (*palette++) = (b << 3) | (b >> 2);
  408.     }
  409. }
  410.  
  411. int berlwall_vh_start(void)
  412. {
  413.     int sx, x,y;
  414.     unsigned char *RAM    =    memory_region(REGION_GFX3);
  415.  
  416.     /* Render the hi-color static backgrounds held in the ROMs */
  417.  
  418.     if ((kaneko16_bg15_bitmap = osd_new_bitmap(256 * 32, 256 * 1, 16)) == 0)
  419.         return 1;
  420.  
  421. /*
  422.     8aba is used as background color
  423.     8aba/2 = 455d = 10001 01010 11101 = $11 $0a $1d
  424. */
  425.  
  426.     for (sx = 0 ; sx < 32 ; sx++)    // horizontal screens
  427.      for (x = 0 ; x < 256 ; x++)    // horizontal pixels
  428.       for (y = 0 ; y < 256 ; y++)    // vertical pixels
  429.       {
  430.             int addr  = sx * (256 * 256) + x + y * 256;
  431.  
  432.             int color = ( RAM[addr * 2 + 0] * 256 + RAM[addr * 2 + 1] ) >> 1;
  433. //                color ^= (0x8aba/2);
  434.  
  435.             plot_pixel( kaneko16_bg15_bitmap,
  436.                         sx * 256 + x, y,
  437.                         Machine->pens[2048 + color] );
  438.       }
  439.  
  440.     return kaneko16_vh_start();
  441. }
  442.  
  443. void berlwall_vh_stop(void)
  444. {
  445.     if (kaneko16_bg15_bitmap)
  446.         osd_free_bitmap(kaneko16_bg15_bitmap);
  447.  
  448.     kaneko16_bg15_bitmap = 0;    // multisession safety
  449. }
  450.  
  451.  
  452. /***************************************************************************
  453.  
  454.                                 Sprites Drawing
  455.  
  456. Offset:            Format:                        Value:
  457.  
  458. 0000.w            Attribute (type 0, older games: shogwarr, berlwall)
  459.  
  460.                     f--- ---- ---- ----        Multisprite: Use Latched Code + 1
  461.                     -e-- ---- ---- ----        Multisprite: Use Latched Color (And Flip?)
  462.                     --d- ---- ---- ----        Multisprite: Use Latched X,Y As Offsets
  463.                     ---c ba-- ---- ----
  464.                     ---- --98 ---- ----        Priority?
  465.                     ---- ---- 7654 32--        Color
  466.                     ---- ---- ---- --1-        X Flip
  467.                     ---- ---- ---- ---0        Y Flip
  468.  
  469.                 Attribute (type 1: gtmr, gtmr2)
  470.  
  471.                     f--- ---- ---- ----        Multisprite: Use Latched Code + 1
  472.                     -e-- ---- ---- ----        Multisprite: Use Latched Color (And Flip?)
  473.                     --d- ---- ---- ----        Multisprite: Use Latched X,Y As Offsets
  474.                     ---c ba-- ---- ----        unused?
  475.                     ---- --9- ---- ----        X Flip
  476.                     ---- ---8 ---- ----        Y Flip
  477.                     ---- ---- 76-- ----        Priority
  478.                     ---- ---- --54 3210        Color
  479.  
  480. 0002.w                                        Code
  481. 0004.w                                        X Position << 6
  482. 0006.w                                        Y Position << 6
  483.  
  484. Note:
  485.     type 2 sprites (berlwall) are like type 0 but the data is held
  486.     in the last 8 bytes of every 16.
  487.  
  488.  
  489. ***************************************************************************/
  490.  
  491.  
  492. /* Map the attribute word to that of the type 1 sprite hardware */
  493.  
  494. #define MAP_TO_TYPE1(attr) \
  495.     if (kaneko16_spritetype != 1)    /* shogwarr, berlwall */ \
  496.     { \
  497.         attr =    ((attr & 0xfc00)     ) | \
  498.                 ((attr & 0x03fc) >> 2) | \
  499.                 ((attr & 0x0003) << 8) ; \
  500.     }
  501.  
  502.  
  503. /* Mark the pens of visible sprites */
  504.  
  505. void kaneko16_mark_sprites_colors(void)
  506. {
  507.     int offs,inc;
  508.  
  509.     int xmin = Machine->drv->visible_area.min_x - (16 - 1);
  510.     int xmax = Machine->drv->visible_area.max_x;
  511.     int ymin = Machine->drv->visible_area.min_y - (16 - 1);
  512.     int ymax = Machine->drv->visible_area.max_y;
  513.  
  514.     int nmax                =    Machine->gfx[0]->total_elements;
  515.     int color_granularity    =    Machine->gfx[0]->color_granularity;
  516.     int color_codes_start    =    Machine->drv->gfxdecodeinfo[0].color_codes_start;
  517.     int total_color_codes    =    Machine->drv->gfxdecodeinfo[0].total_color_codes;
  518.  
  519.     int sx = 0;
  520.     int sy = 0;
  521.     int scode = 0;
  522.     int scolor = 0;
  523.  
  524.     switch (kaneko16_spritetype)
  525.     {
  526.         case 2:        offs = 8; inc = 16;    break;
  527.         default:    offs = 0; inc = 8;    break;
  528.     }
  529.  
  530.     for ( ;  offs < spriteram_size ; offs += inc)
  531.     {
  532.         int    attr    =    READ_WORD(&spriteram[offs + 0]);
  533.         int    code    =    READ_WORD(&spriteram[offs + 2]) % nmax;
  534.         int    x        =    READ_WORD(&spriteram[offs + 4]);
  535.         int    y        =    READ_WORD(&spriteram[offs + 6]);
  536.  
  537.         /* Map the attribute word to that of the type 1 sprite hardware */
  538.         MAP_TO_TYPE1(attr)
  539.  
  540.         if (x & 0x8000)    x -= 0x10000;
  541.         if (y & 0x8000)    y -= 0x10000;
  542.  
  543.         x /= 0x40;        y /= 0x40;
  544.  
  545.         if (attr & 0x8000)        scode++;
  546.         else                    scode = code;
  547.  
  548.         if (!(attr & 0x4000))    scolor = attr % total_color_codes;
  549.  
  550.         if (attr & 0x2000)        { sx += x;    sy += y; }
  551.         else                    { sx  = x;    sy  = y; }
  552.  
  553.         /* Visibility check. No need to account for sprites flipping */
  554.         if ((sx < xmin) || (sx > xmax))    continue;
  555.         if ((sy < ymin) || (sy > ymax))    continue;
  556.  
  557.         memset(&palette_used_colors[color_granularity * scolor + color_codes_start + 1],PALETTE_COLOR_USED,color_granularity - 1);
  558.     }
  559.  
  560. }
  561.  
  562.  
  563.  
  564. /* Draw the sprites */
  565.  
  566. void kaneko16_draw_sprites(struct osd_bitmap *bitmap, int priority)
  567. {
  568.     int offs,inc;
  569.  
  570.     int max_x    =    Machine->drv->screen_width  - 16;
  571.     int max_y    =    Machine->drv->screen_height - 16;
  572.  
  573.     int sx = 0;
  574.     int sy = 0;
  575.     int scode = 0;
  576.     int sattr = 0;
  577.     int sflipx = 0;
  578.     int sflipy = 0;
  579.  
  580.     priority = ( priority & 3 ) << 6;
  581.  
  582.     switch (kaneko16_spritetype)
  583.     {
  584.         case 2:        offs = 8; inc = 16;    break;
  585.         default:    offs = 0; inc = 8;    break;
  586.     }
  587.  
  588.     for ( ;  offs < spriteram_size ; offs += inc)
  589.     {
  590.         int    attr    =    READ_WORD(&spriteram[offs + 0]);
  591.         int    code    =    READ_WORD(&spriteram[offs + 2]);
  592.         int    x        =    READ_WORD(&spriteram[offs + 4]);
  593.         int    y        =    READ_WORD(&spriteram[offs + 6]);
  594.  
  595.         /* Map the attribute word to that of the type 1 sprite hardware */
  596.         MAP_TO_TYPE1(attr)
  597.  
  598.         if (x & 0x8000)    x -= 0x10000;
  599.         if (y & 0x8000)    y -= 0x10000;
  600.  
  601.         x /= 0x40;        y /= 0x40;
  602.  
  603.         if (attr & 0x8000)        scode++;
  604.         else                    scode = code;
  605.  
  606.         if (!(attr & 0x4000))
  607.         {
  608.             sattr  = attr;
  609.             sflipx = attr & 0x200;    sflipy = attr & 0x100;
  610.         }
  611.  
  612.         if (attr & 0x2000)        { sx += x;    sy += y; }
  613.         else                    { sx  = x;    sy  = y; }
  614.  
  615.         if ((sattr & 0xc0) != priority)    continue;
  616.  
  617. #ifdef MAME_DEBUG
  618.     if ( debugsprites && ( ((sattr >> 6) & 3) != debugsprites-1 ) )    continue;
  619. #endif
  620.  
  621.         if (flipsprites & 2) { sx = max_x - sx;        sflipx = !sflipx; }
  622.         if (flipsprites & 1) { sy = max_y - sy;        sflipy = !sflipy; }
  623.  
  624.         drawgfx(bitmap,Machine->gfx[1],
  625.                 scode,
  626.                 sattr,
  627.                 sflipx, sflipy,
  628.                 sx,sy,
  629.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  630.  
  631.         /* let's get back to normal to support multi sprites */
  632.         if (flipsprites & 2) { sx = max_x - sx;        sflipx = !sflipx; }
  633.         if (flipsprites & 1) { sy = max_y - sy;        sflipy = !sflipy; }
  634.     }
  635.  
  636. }
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643. /***************************************************************************
  644.  
  645.                                 Screen Drawing
  646.  
  647. ***************************************************************************/
  648.  
  649. void kaneko16_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  650. {
  651.     int flag;
  652.     int layers_ctrl = -1;
  653.     int layers_flip = READ_WORD(&kaneko16_layers1_regs[0x08]);
  654.  
  655.     tilemap_set_flip(fg_tilemap,((layers_flip & 0x0001) ? TILEMAP_FLIPY : 0) |
  656.                                 ((layers_flip & 0x0002) ? TILEMAP_FLIPX : 0) );
  657.  
  658.     tilemap_set_flip(bg_tilemap,((layers_flip & 0x0100) ? TILEMAP_FLIPY : 0) |
  659.                                 ((layers_flip & 0x0200) ? TILEMAP_FLIPX : 0) );
  660.  
  661.     tilemap_set_scrollx(fg_tilemap, 0, READ_WORD(&kaneko16_layers1_regs[0x00]) >> 6 );
  662.     tilemap_set_scrolly(fg_tilemap, 0, READ_WORD(&kaneko16_layers1_regs[0x02]) >> 6 );
  663.  
  664.     tilemap_set_scrollx(bg_tilemap, 0, READ_WORD(&kaneko16_layers1_regs[0x04]) >> 6 );
  665.     tilemap_set_scrolly(bg_tilemap, 0, READ_WORD(&kaneko16_layers1_regs[0x06]) >> 6 );
  666.  
  667.  
  668. #ifdef MAME_DEBUG
  669. debugsprites = 0;
  670. if (keyboard_pressed(KEYCODE_Z))
  671. {
  672. int msk = 0;
  673.  
  674.     if (keyboard_pressed(KEYCODE_Q))    { msk |= 0x01;}
  675.     if (keyboard_pressed(KEYCODE_W))    { msk |= 0x02;}
  676.     if (keyboard_pressed(KEYCODE_E))    { msk |= 0x04;}
  677.     if (keyboard_pressed(KEYCODE_R))    { msk |= 0x10;}
  678.     if (keyboard_pressed(KEYCODE_T))    { msk |= 0x20;}
  679.     if (keyboard_pressed(KEYCODE_A))    { msk |= 0x08; debugsprites = 1;}
  680.     if (keyboard_pressed(KEYCODE_S))    { msk |= 0x08; debugsprites = 2;}
  681.     if (keyboard_pressed(KEYCODE_D))    { msk |= 0x08; debugsprites = 3;}
  682.     if (keyboard_pressed(KEYCODE_F))    { msk |= 0x08; debugsprites = 4;}
  683.     if (msk != 0) layers_ctrl &= msk;
  684. }
  685. #endif
  686.  
  687.  
  688.     tilemap_update(ALL_TILEMAPS);
  689.  
  690.     palette_init_used_colors();
  691.  
  692.     kaneko16_mark_sprites_colors();
  693.  
  694.     if (palette_recalc())    tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  695.  
  696.     tilemap_render(ALL_TILEMAPS);
  697.  
  698.     flag = TILEMAP_IGNORE_TRANSPARENCY;
  699.     if (kaneko16_bg15_bitmap)
  700.     {
  701. /*
  702.     firstscreen    ?                (hw: b8,00/06/7/8/9(c8). 202872 = 0880)
  703.     press start    ?                (hw: 80-d0,0a. 202872 = 0880)
  704.     teaching    ?                (hw: e0,1f. 202872 = 0880 )
  705.     hiscores    !rom5,scr1($9)    (hw: b0,1f. 202872 = )
  706.     lev1-1        rom6,scr2($12)    (hw: cc,0e. 202872 = 0880)
  707.     lev2-1        ?                (hw: a7,01. 202872 = 0880)
  708.     lev2-2        rom6,scr1($11)    (hw: b0,0f. 202872 = 0880)
  709.     lev2-4        rom6,scr0($10)    (hw: b2,10. 202872 = 0880)
  710.     lev2-6?        rom5,scr7($f)    (hw: c0,11. 202872 = 0880)
  711.     lev4-2        rom5,scr6($e)    (hw: d3,12. 202872 = 0880)
  712.     redcross    ?                (hw: d0,0a. 202872 = )
  713. */
  714.         int select    =    READ_WORD(&kaneko16_bg15_select[0]);
  715. //        int reg        =    READ_WORD(&kaneko16_bg15_reg[0]);
  716.         int flip    =    select & 0x20;
  717.         int sx, sy;
  718.  
  719.         if (flip)    select ^= 0x1f;
  720.  
  721.         sx        =    (select & 0x1f) * 256;
  722.         sy        =    0;
  723.  
  724.         copybitmap(
  725.             bitmap, kaneko16_bg15_bitmap,
  726.             flip, flip,
  727.             -sx, -sy,
  728.             &Machine->drv->visible_area, TRANSPARENCY_NONE,0 );
  729.  
  730.         flag = 0;
  731.     }
  732.  
  733.     if (layers_ctrl & 0x01)    tilemap_draw(bitmap, bg_tilemap, flag);
  734.     else                    osd_clearbitmap(Machine->scrbitmap);
  735.  
  736.     if (layers_ctrl & 0x02)    tilemap_draw(bitmap, fg_tilemap, 0);
  737.     if (layers_ctrl & 0x08)    kaneko16_draw_sprites(bitmap,0);
  738.  
  739.     if (layers_ctrl & 0x04)    tilemap_draw(bitmap, fg_tilemap, 1);
  740.     if (layers_ctrl & 0x08)    kaneko16_draw_sprites(bitmap,1);
  741.  
  742.     if (layers_ctrl & 0x10)    tilemap_draw(bitmap, fg_tilemap, 2);
  743.     if (layers_ctrl & 0x08)    kaneko16_draw_sprites(bitmap,2);
  744.  
  745.     if (layers_ctrl & 0x20)    tilemap_draw(bitmap, fg_tilemap, 3);
  746.     if (layers_ctrl & 0x08)    kaneko16_draw_sprites(bitmap,3);
  747. }
  748.